import '../../css/addNote.css';
import ajax from '../../utils/ajax';

const form = document.forms.add;
form.onsubmit = form_onsubmit;


function form_onsubmit(e) {
  e.preventDefault();


  if (!form.title.value || !form.content.value) {
    alert(内容不能为空);
    return;
  }

  ajax('post', '/api/addNote', {
    title: form.title.value,
    content: form.content.value
  }).then(result => {
    if (result.flag) {
      alert(result.msg);
      if (confirm('您还需要发布吗？')) {
        form.reset();
      } else {
        location.assign('/index.html')
      }
    }
  })
}